package com.kpf.springcloud.controller;

import com.kpf.springcloud.common.ResultJson;
import com.kpf.springcloud.service.FeignClientUserServer;
import com.kpf.springcloud.vo.PayResultVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author shiwen
 * @date 2021/3/9
 */
@RestController
@Api(value = "支付相关接口", description = "支付相关接口") //swagger接口配置
public class PayConsumerController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private FeignClientUserServer feignClientUserServer;

    /**
     * 生成微信支付二维码
     *
     * @param totalFee   金额(分)
     */
    @PostMapping("/consumer/pay/createNative")
    public ResultJson<PayResultVO> createNative(@RequestParam("totalFee") String totalFee,
                                                @RequestParam("body") String body,
                                                HttpServletRequest request, HttpServletResponse response) {
        return feignClientUserServer.createNative(totalFee, body);
    }

    /**
     * 查询订单支付状态, 支付成功后可以回调这个接口查询订单状态
     *
     * @param outTradeNo 订单号
     * @return 支付状态
     */
    @GetMapping("/consumer/pay/queryOrder")
    public ResultJson<String> queryOrder(@RequestParam("outTradeNo") String outTradeNo) {
        return feignClientUserServer.queryOrder(outTradeNo);
    }

}